---
title: "Pivot Result Columns"
enterprise: true
---
The grid generates pivot result columns to display the aggregated values for each unique permutation of pivot values.

{% gridExampleRunner title="Pivot Result Column Summary Example" name="pivot-result-summary"  /%}

## Column Definitions

Pivot Result Columns inherit [Column Definitions](./column-definitions) from the value column that they were created from. It is also possible to extend this definition further
to specifically customise pivot result columns using the `processPivotResultColDef` grid option.

{% apiDocumentation source="grid-options/properties.json" section="rowPivoting" names=["processPivotResultColDef"] /%}

In the example below, the `Gold` column has `cellStyle: { backgroundColor: '#f2e287' }` applied, this is then inherited by the pivot result columns,
causing all of the `sum(Gold)` columns to have a gold background. Note that the `Silver` column does not have this background so neither do the `sum(Silver)` columns.

The grid option `processPivotResultColDef` is then also used, which sets the text colour of all the pivot result columns to `#2f73ff`.

{% gridExampleRunner title="Column Definitions Example" name="column-definitions-example"  /%}

This uses the following configuration to both inherit and modify column definitions on the pivot result columns:

```{% frameworkTransform=true %}
const gridOptions = {
    columnDefs: [
        // ...other column definitions
        { field: 'gold', aggFunc: 'sum', cellStyle: { backgroundColor: '#f2e287' } },
        { field: 'silver', aggFunc: 'sum', cellStyle: {} },
    ],
    pivotMode: true,
    processPivotResultColDef: (colDef) => {
        colDef.cellStyle.color = '#2f73ff'; // the params are mutated directly, not returned
    },
}
```

## Filtering

When pivot mode is enabled, you can [Filter](./filtering-overview/) on the pivot result columns by setting the `filter` attribute on your value column.

{% gridExampleRunner title="Filtering Pivot Result Columns" name="secondary-columns-filter" /%}

As pivot values are all aggregates, filtering out rows will not re-aggregate the parent rows. Refer to [Filtering Aggregated Values](./aggregation-filtering/#filtering-for-aggregated-values) for more information.

{% note %}
Pivot result columns inherit the properties of the value column from which they are generated. However, setting `filter: true` will instead
default to a [Number Filter](./filter-number/) in the case of a pivot result column. The [Set Filter](./filter-set/) cannot be used for filtering pivot result columns.
{% /note %}

## Best Practices

### Limiting Column Generation

When pivoting, changes in data, aggregation or pivot columns can cause the number of generated columns to scale exponentially.
This can cause performance issues such as long delays in rendering, and often the resulting view would be unmanageable for the user.

To prevent this from happening, you can set the `pivotMaxGeneratedColumns` option. When the grid generates a number of pivot columns
exceeding this value, it halts column generation, clears the view, and fires the `onPivotMaxColumnsExceeded` event to allow your
application to intervene.

{% gridExampleRunner title="Extreme Pivot Handling" name="extreme-pivot" exampleHeight=600 /%}

In the example above, pivoting by the `Athlete` column will instead trigger the `pivotMaxColumnsExceeded` event, which logs an error in the browser console.

The example above demonstrates the following configuration:
```{% frameworkTransform=true %}
const gridOptions = {
    pivotMode: true,
    pivotMaxGeneratedColumns: 1000,
    onPivotMaxColumnsExceeded: () => {
        console.error(
            'The limit of 1000 generated columns has been exceeded. Either remove pivot or aggregations from some columns or increase the limit.'
        );
    },
}
```

## Next Up

Continue to the next section to learn [Pivot Column Groups](./pivoting-column-groups/).
